<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="/WEB-INF/tlds/spring.tld"%>
<%@ taglib prefix="c" uri="/WEB-INF/tlds/c.tld"%>
<c:set var="BasePath" value="${pageContext.request.contextPath}"></c:set>
<c:set var="Plugins" value="${pageContext.request.contextPath}/res/plugins"></c:set>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>新增品牌</title>
<link href="${Plugins}/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="${Plugins}/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
<script src="${Plugins}/jquery/jquery-1.4.4.min.js"	type="text/javascript"></script>
<script src="${Plugins}/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/jquery.validate.min.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/jquery.metadata.js" type="text/javascript"></script>
<script src="${Plugins}/jquery-validation/messages_cn.js" type="text/javascript"></script>
<script src="${BasePath}/res/js/common/jquery.form.js" type="text/javascript"></script>
<script type="text/javascript" src="${BasePath}/res/js/ligerCommon.js"></script>
<script src="${BasePath}/res/js/common/jquery.validate.method.js" type="text/javascript"></script>
<script src="${Plugins}/datepicker/WdatePicker.js" type="text/javascript"></script>
<script src="${BasePath}/res/js/product/commodityCat.js" type="text/javascript"></script>

<style type="text/css">
    body{ font-size:12px;}
    .l-table-edit {}
    .l-table-edit-td{ padding:4px;}
    .l-button-submit,.l-button-test{width:80px; float:left; margin-left:10px; padding-bottom:2px;}
    .l-verify-tip{ left:230px; top:120px;}
    .p-tab .s-lab{font-size:12px;font-family:"微软雅黑",​"宋体",​Arial,​sans-serif;}
	input.l-textarea{width:170px;height:20px;font-size:12px;}
	 .navbar {
		height: 20px;
		border-bottom: #E6E6E6 solid 1px;
		line-height: 20px;
	}
	select{margin-right: 10px;}
	li{margin-top: 5px;}
</style>
</head>
<body style="padding:10px">
<div class="navbar">
		<span>您当前的位置：</span>
		商品管理 &gt;品牌列表&gt; 修改品牌
</div>
<form name="form1" method="post" action="update_brand.do" id="form1">
<input type="hidden" name="brandNo" id="brandNo"  value="${brand.brandNo}">
<br>
<table cellpadding="0" cellspacing="0" class="l-table-edit p-tab" >
	<tr>
        <td align="right" class="l-table-edit-td s-lab" style="vertical-align: top;"><font color="red">*</font>商品分类:</td>
        <td align="left" class="l-table-edit-td s-lab">
        	<input type="hidden" id="catNo" name="catNo" value="${catNo}">
        	<div style="float: left;" id="catDiv"></div>
			<input class="l-button-test" onclick="addNewCat();" type="button" value="添加分类" />
		</td>
        <td align="left"></td>
    </tr>
    <tr>
        <td align="right" class="l-table-edit-td s-lab"></td>
        <td align="left" class="l-table-edit-td s-lab">
        	<ul id="addcat">
			</ul>
		</td>
        <td align="left"></td>
    </tr>
    <tr>
        <td align="right" class="l-table-edit-td s-lab"><font color="red">*</font>品牌名称:</td>
        <td align="left" class="l-table-edit-td s-lab"><input name="brandName"  type="text" maxlength="20" class="l-textarea" id="brandName" validate="{required:true,minlength:1,maxlength:20}" value="${brand.brandName}"/></td>
        <td align="left"></td>
    </tr>
    <tr>
        <td align="right" class="l-table-edit-td s-lab"><font color="red">*</font>编码:</td>
        <td align="left" class="l-table-edit-td s-lab"><input maxlength="4" name="no" id="no"  type="text" class="l-textarea" id="brandName"  title="请输入4位字符的编码"  validate="{alphanumeric:true,required:true,rangelength:[4,4]}"  value="${brand.no}"/></td>
        <td align="left"></td>
    </tr>
     <tr>
        <td align="right" class="l-table-edit-td s-lab">网址:</td>
        <td align="left" class="l-table-edit-td s-lab"><input maxlength="50" name="brandUrl" type="text" class="l-textarea" id="brandUrl" validate="{url:true}" value="${brand.brandUrl}" /></td>
        <td align="left"></td>
    </tr>
	
	 <tr>
        <td align="right" class="l-table-edit-td s-lab">品牌描述：</td>
        <td align="left" class="l-table-edit-td s-lab"><textarea onkeyup="this.value=this.value.substring(0,2000);" rows="5" cols="20" name="description"   >${brand.description}</textarea></td>
        <td align="left"></td>
    </tr>
</table>
<input type="submit" value="保存" id="Button1" class="l-button l-button-submit" /> 
<input type="button" value="取消" name="tests"  id="tests" class="l-button l-button-test" />
</form>
<div style="display:none">
<!--  数据统计代码 --></div>

<script type="text/javascript">
var basePath="${BasePath}";
var catNo = '${catNo}';
var catNos = '${catNos}';
$(function() {
	//初始加载分类
	parentCat(catNo);
	if(catNos != null){
		catNos = $.parseJSON(catNos);
		for ( var i in catNos) {
			readonlyCat(catNos[i].catNo);
		}
	}
});

//修改分类
function getProCat(o){
	$("select[name=level]").eq($(o).index()).nextAll().remove();
	
	if(o.value == "" || o.value == null){
		$("#catNo").val($("select[name=level]").eq($(o).index()-1).val());
	}else{
		$("#catNo").val(o.value);
	}
	if(o.value == "0") return false;
	sonCat(o.value);
}

function addNewCat() {
	if($("select[name=level]").eq(0).val() == 0) {
		$.ligerDialog.warn("请选择分类");
		return false;
	}
	var iscat = true;
	$("input[name=catNos]").each(function() {
		if($("#catNo").val() == $(this).val()){
			$.ligerDialog.warn("该分类已经存在");
			iscat = false;
			return false;
		}
	});
	if(!iscat) return iscat;
	readonlyCat($("#catNo").val());
}

//验证编号是否重复
$("#no").change(function() {
	var no = $("#no").val();
	if(no!=""){
		$.post(
				basePath + '/product/brandmgt/validationRepeatNo.do',
				{no : no},
			 	function(data) {
					if(data == "success"){
						window.parent.$.ligerDialog.error("该编号已存在，请重新输入！");
						$("#no").val("");
					};
		});
	}

});
//验证品牌名称是否存在
$("#brandName").change(function() {
	var brandName=$("#brandName").val();
	var url = basePath + '/product/brandmgt/validationRepeatNo.do';
	if(brandName!=""){
		$.post(
				url,{brandName:$("#brandName").val()},
				function(data){
					if(data == "success"){
						window.parent.$.ligerDialog.error("该品牌名称已存在");
						$("#brandName").val("");
					};
				}
			);
	}
	
});
$(function ()
		{
			//validate
		    $.metadata.setType("attr", "validate");
		    var v = $("form").validate({
		        errorPlacement: function (lable, element)
		        {
		        	lable.ligerHideTip();
		            if (element.hasClass("l-textarea"))
		            {
		                element.ligerTip({ content: lable.html(), target: element[0] }); 
		            }
		            else if (element.hasClass("l-text-field"))
		            {
		                element.parent().ligerTip({ content: lable.html(), target: element[0] });
		            }
		            else
		            {
		                lable.appendTo(element.parents("td:first").next("td"));
		            }
		        }
		    ,
		        success: function (lable)
		        {
		            lable.ligerHideTip();
		            lable.remove();
		        },
		        submitHandler:function()
		        {
		            $("form .l-text,.l-textarea").ligerHideTip();
		            if($("ul li").length < 1){
		            	$.ligerDialog.warn("请添加分类");
		            	return false;
		            }
		            var options = {
		            		type: 'POST',
		            		beforeSend: function(){
		            			$("#form1").find(":submit,:button").attr("disabled", true);
		            		},
		            		success: function(data){
		            			if(data=="success") {
		            				window.parent.f_tip('修改成功');
		           					close_liger_tab();
		            			} else {
		            				window.parent.f_tip('修改失败');
		            			}
		            		}
		            	}, $form1 = $("#form1");
		           $form1.ajaxSubmit(options);
		             return false;
		        }
		    });
		}); 
// 取消
$("#tests").click(function() {
	close_liger_tab();
});	
</script>
</body>
</html>